package srv

import (
	"fmt"
	"jgt-oper/src/context"
)

// Demo 示例接口
type Demo struct {
}

// Get ?name=
func (a *Demo) Get(ctx *context.Context) error {
	name := ctx.Query("name")

	data := map[string]interface{}{
		"name": fmt.Sprintf("Hello,%s", name),
	}
	return ctx.ResSuccess(data)
}

// Post ...
func (a *Demo) Post(ctx *context.Context) error {
	var reqData struct {
		Name string `json:"name"`
	}

	if err := ctx.DecodeJSON(&reqData); err != nil {
		return ctx.ResErrBadRequest(err)
	}

	data := map[string]interface{}{
		"name": fmt.Sprintf("Hello,%s", reqData.Name),
	}
	return ctx.ResSuccess(data)
}
